
#include"../include/p.h"
#include<stdio.h>//数据库的增删改查！
//界面；
int sqlite3zsgc(int tcp_socket)
{
	char mycreate[50]={"create"};
	char myinsert[50]={"insert"};
	char myrm[50]={"delete"};
//	char myupdata[50]={"updata"};
	char myselect[50]={"select"};
	char tuichu[50]={"quit"};
	
	while(1)
	{
		printf("欢迎使用云存储，请选择您需要的功能 \n");
		printf("1.创建新的表\n");
		printf("2.在表中插入mod\n");
		printf("3.删除表\n");
		printf("4.查找表中的信息\n");
		printf("0.退出表 进入上传下载功能\n");
		int op=-1;
		scanf("%d",&op);
		//getchar();
		switch(op)
		{
			case 0:
					{

						send(tcp_socket,tuichu,sizeof(tuichu),0);
						bzero(tuichu,sizeof(tuichu));
						return 2;

					}
			case 1:
				   {
					   printf("创建表～\n");
						int ret=send(tcp_socket,"create",strlen("create"),0);

					   printf("创建表～\n");
						if(ret<0)
						{
							perror(" error:");
						}
						bzero(mycreate,sizeof(mycreate));
						recv(tcp_socket,mycreate,sizeof(mycreate),0);
						printf("%s",mycreate);
						printf("\n");
						bzero(mycreate,sizeof(mycreate));
						scanf("%s",mycreate);
						//fgets(mycreate,sizeof(mycreate),stdin);
						send(tcp_socket,mycreate,sizeof(mycreate),0);
						printf("%s",mycreate);
						bzero(mycreate,sizeof(mycreate));
						//发送表名，看服务器反馈结果
						recv(tcp_socket,mycreate,sizeof(mycreate),0);
						printf("%s",mycreate);
						bzero(mycreate,sizeof(mycreate));
						
						break;
				   }
			case 2:
				   {
					   send(tcp_socket,myinsert,sizeof(myinsert),0);
					   bzero(myinsert,sizeof(myinsert));
					   recv(tcp_socket,myinsert,sizeof(myinsert),0);
					   printf("%s\n",myinsert);
					   printf("\n");//传入表名
					   bzero(myinsert,sizeof(myinsert));
					   scanf("%s",myinsert);
					   getchar();
					   send(tcp_socket,myinsert,sizeof(myinsert),0);
					   //接收服务器端的回应
					   recv(tcp_socket,myinsert,sizeof(myinsert),0);
					   printf("%s\n",myinsert);
					   printf("\n");//传入数据
					   bzero(myinsert,sizeof(myinsert));
					   //scanf("%s",myinsert);
					   fgets(myinsert,sizeof(myinsert),stdin);
					   printf("%s\n",myinsert);
					   send(tcp_socket,myinsert,sizeof(myinsert),0);
					   //输入参数 id name 
					   printf("%s\n",myinsert);
					   recv(tcp_socket,myinsert,sizeof(myinsert),0);
					   if(strncmp(myinsert,"newmod",6)==0)
					   {
						   printf("mod插入成功！\n");
						   break;
					   }
					   else
					   {
						   printf("mod 插入失败！\n");
						   break;
					   }
				   }
			case 3:
				   {
					   printf("删除\n");
					   send(tcp_socket,myrm,sizeof(myrm),0);
					   bzero(myrm,sizeof(myrm));
					   recv(tcp_socket,myrm,sizeof(myrm),0);
					   printf("%s\n",myrm);
					   printf("\n");
					   //传入表名
					   bzero(myrm,sizeof(myrm));
					   printf("begin\n");
					   scanf("%s",myrm);
					   //fgets(myrm,sizeof(myrm),stdin);
					   printf("end\n");
					   send(tcp_socket,myrm,sizeof(myrm),0);
					   bzero(myrm,sizeof(myrm));
					   //再传入表中要删除的id
				/*	   recv(tcp_socket,myrm,sizeof(myrm),0);
					   printf("%s\n",myrm);
					   bzero(myrm,sizeof(myrm));
					   fgets(myrm,sizeof(myrm),stdin);
					   send(tcp_socket,myrm,sizeof(myrm),0);
					   bzero(myrm,sizeof(myrm));
				*/	   recv(tcp_socket,myrm,sizeof(myrm),0);
					   printf("%s",myrm);


					   if(strncmp(myrm,"ok",2)==0)
					   {
						   printf("删除成功\n");
						   break;
					   }
					   else if(strncmp(myrm,"no",2)==0)
					   {
						   printf("数据库中没有此表\n");
						   break;
					   }
					   else
					   {
						   printf("删除失败\n");
						   break;

					   }
				   }
			case 4:
				   {
					   printf("查找\n");
					   send(tcp_socket,myselect,sizeof(myselect),0);
					   bzero(myselect,sizeof(myselect));
					   //接收服务器端的回应
					   recv(tcp_socket,myselect,sizeof(myselect),0);
					   printf("%s\n",myselect);
					   bzero(myselect,sizeof(myselect));
					   scanf("%s",myselect);
					   send(tcp_socket,myselect,sizeof(myselect),0);
					   bzero(myselect,sizeof(myselect));
					   recv(tcp_socket,myselect,sizeof(myselect),0);
					   printf("%s",myselect);
					   if(strcmp(myselect,"ok")==0)
					   {
						   printf("查询成功！\n");
						   break;
					   }
					   else
					   {
						   printf("查询失败\n");
						   break;
					   }
				   }

			default:
				   {
					   printf("选项不匹配！\n");
					   return -1;
				   }

		}

	}
	return 0;

}

